package com.yanqu.road.logic.bussiness.activity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.yanqu.road.dao.db.DBPoolManager;
import com.yanqu.road.entity.activity.harps.HarpsRewardInfo;
import com.yanqu.road.entity.activity.harps.HarpsUserData;
import com.yanqu.road.entity.activity.hell.*;
import com.yanqu.road.logic.bussiness.DaoHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HarpsBusiness {

    // 配置
    public static <T> Map<Integer, T> getGenericConfigMap(int activityId, Class<T> type) {
        return DaoHelper.getGenericConfigDaoImpl().getGenericConfigMap(activityId, type);
    }

    public static Map<Integer, Map<Integer, HarpsRewardInfo>> getHarpsRewardInfo(int activityId, long userId) {
        return DaoHelper.getHarpsRewardInfoDaoImpl().getHarpsRewardInfo(activityId, userId);
    }

    public static boolean addHarpsRewardInfo(HarpsRewardInfo data) {
        return DaoHelper.getHarpsRewardInfoDaoImpl().add(data);
    }

    public static boolean updateHarpsRewardInfo(HarpsRewardInfo data) {
        return DaoHelper.getHarpsRewardInfoDaoImpl().update(data);
    }

    public static HarpsUserData getHarpsUserData(int activityId, long userId) {
        return DaoHelper.getHarpsUserDaoImpl().getHarpsUserData(activityId, userId);
    }

    public static boolean addHarpsUserData(HarpsUserData data) {
        return DaoHelper.getHarpsUserDaoImpl().add(data);
    }

    public static boolean updateHarpsUserData(HarpsUserData data) {
        return DaoHelper.getHarpsUserDaoImpl().update(data);
    }

    public static void testHarpsReward() {
        DBPoolManager.getInstance("");
        List<HarpsRewardInfo> list = new ArrayList<>();
        HarpsRewardInfo harpsRewardInfo1 = new HarpsRewardInfo();
        harpsRewardInfo1.setActivityId(1);
        harpsRewardInfo1.setUserId(1);
        harpsRewardInfo1.setId(1);
        harpsRewardInfo1.setNo(0);
        list.add(harpsRewardInfo1);
        HarpsRewardInfo harpsRewardInfo21 = new HarpsRewardInfo();
        harpsRewardInfo21.setActivityId(2);
        harpsRewardInfo21.setUserId(2);
        harpsRewardInfo21.setId(2);
        harpsRewardInfo21.setNo(1);
        list.add(harpsRewardInfo21);
        HarpsRewardInfo harpsRewardInfo20 = new HarpsRewardInfo();
        harpsRewardInfo20.setActivityId(2);
        harpsRewardInfo20.setUserId(2);
        harpsRewardInfo20.setId(2);
        harpsRewardInfo20.setNo(0);
        list.add(harpsRewardInfo20);
        for (HarpsRewardInfo harpsRewardInfo : list) {
            boolean b = addHarpsRewardInfo(harpsRewardInfo);
            if (!b) {
                System.out.println("插入错误" + JSONArray.toJSONString(harpsRewardInfo));
                return;
            }
        }

        Map<Integer, Map<Integer, HarpsRewardInfo>> harpsRewardInfo = getHarpsRewardInfo(1, 2);
        if (!harpsRewardInfo.isEmpty()) {
            System.out.println("获取错误12" + JSONArray.toJSONString(harpsRewardInfo));
            return;
        }
        Map<Integer, Map<Integer, HarpsRewardInfo>> harpsRewardInfo2 = getHarpsRewardInfo(1, 1);
        if (harpsRewardInfo2.size() != 1) {
            System.out.println("获取错误11" + JSONArray.toJSONString(harpsRewardInfo2));
            return;
        }
        Map<Integer, Map<Integer, HarpsRewardInfo>> harpsRewardInfo3 = getHarpsRewardInfo(2, 2);
        if (harpsRewardInfo2.size() != 2) {
            System.out.println("获取错误22" + JSONArray.toJSONString(harpsRewardInfo2));
            return;
        }

        Map<Integer, HarpsRewardInfo> harpsRewardInfos = harpsRewardInfo3.get(2);
        HarpsRewardInfo harpsRewardInfo4 = harpsRewardInfos.get(1);
        System.out.println("更新" + JSONArray.toJSONString(harpsRewardInfo4));
        harpsRewardInfo4.setIsGetReward(true);
        updateHarpsRewardInfo(harpsRewardInfo4);
    }
}
